package main.model.island;

import java.util.Random;

import main.model.island.grid.Grid;
import main.model.island.grid.GridFactory;
import main.model.island.grid.GridType;


public class RandomIsland {
	
	static IslandInterface island;
	static Random r = new Random();
	
	public static IslandInterface createRandomIsland(){
		island = new ArrayIsland();
		island = createRandomIsland(island.getXSize(), island.getYSize());
		
		return island;
	}
	
	public static IslandInterface createRandomIsland(int xd, int yd){
		island = new ArrayIsland(xd , yd);
		for(int x = 0; x < island.getXSize(); x++){
			for(int y = 0; y < island.getYSize(); y++){
				Grid g = GridFactory.newGrid(getRandomGridType());
				island.setGrid(x, y, g);

				//System.out.println("Rand x "+x+", y "+y+", g "+island.getGrid(x, y));
			}
		}
		return island;
	}
	
	
	/**
	 * Chooses a GridType at random.
	 * <p>
	 * Chooses with probabilities of sand half, grass a quarter, tree a quarter.
	 * @return
	 */
	public static GridType getRandomGridType(){
		GridType g;
		if(r.nextInt(2) == 0){
			if(r.nextInt(3) == 0){g = GridType.TREE;}
			else{g = GridType.GRASS;}
		}else{g = GridType.SAND;}
		return g;
	}
}
